package io.github.talelin.latticy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.talelin.autoconfigure.exception.NotFoundException;
import io.github.talelin.latticy.bo.BannerItemBO;
import io.github.talelin.latticy.mapper.BannerItemMapper;
import io.github.talelin.latticy.model.BannerItem;
import io.github.talelin.latticy.service.BannerItemService;
import io.github.talelin.latticy.common.util.BeanCopyUtil;
import org.springframework.stereotype.Service;

/**
 * BannerItem服务层
 *
 * @author YiHua
 * @date 2021/11/26 12:58 上午
 */
@Service
public class BannerItemServiceImpl extends ServiceImpl<BannerItemMapper, BannerItem> implements BannerItemService {

    /**
     * 删除一个bannerItem
     *
     * @param id bannerItemId
     */
    @Override
    public void delete(Integer id) {
        BannerItem bannerItem = this.getById(id);
        if (bannerItem == null) {
            throw new NotFoundException(20001);
        }
        this.getBaseMapper().deleteById(id);
    }

    /**
     * 新增、修改bannerItem
     *
     * @param bannerItemBO bannerItem的入参信息
     * @param id           bannerItemId
     */
    @Override
    public void update(BannerItemBO bannerItemBO, Integer id) {
        BannerItem bannerItem = this.getById(id);
        if (bannerItem == null) {
            throw new NotFoundException(20001);
        }
        BeanCopyUtil.copy(bannerItemBO, bannerItem);
        this.updateById(bannerItem);
    }
}
